<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2020 幕小铺科技（大连）有限公司
// +----------------------------------------------------------------------
// | 2020/03/14
// +----------------------------------------------------------------------

namespace app\video\model;

use think\Model;

/**
 * 视频收藏 模型
 * @package app\user_center\model
 */
class VideoPlayCollect extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'xm_video_play_collect';

    /**
     * 添加数据
     * @param int $uid 用户id
     * @param int $play_id 视频id
     * @author jason wang <120907037@qq.com>
     * @return bool
     */
    public function addData($uid, $play_id){
        $video_info = model('video/VideoPlay') -> getPlayFatherPlayInfo($play_id);
		$play_id = $video_info['data'];//关联的视频id	
		
        $this -> uid             = $uid;
        $this -> play_id         = $play_id;
        $res = $this -> isUpdate(false) -> save();
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }

    /**
     * 删除数据
     * @param int $uid 用户id
     * @param int $play_id 视频id
     * @author jason wang <120907037@qq.com>
     * @return bool
     */
    public function deleteData($uid, $play_id){
        $map        = [];
        $map['uid']     = $uid;
        $map['play_id'] = $play_id;
        $res = self::destroy(function($query) use ($map){
            $query->where($map);
        });
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }

    /**
     * 获取用户收藏 的视频列表
     * @param int $uid 用户id
     * @param int $page 页码（默认1）
     * @author shiqiang <976162041@qq.com>
     * @return bool
     */
	public function getListByUid($uid){
		$list = $this -> where('uid', $uid) -> order('create_time' ,'desc') -> paginate();
        return array_out(200, 'success', $list);
    }


    /**
     * 获取视频收藏 用户列表
     * @param int $play_id 视频id
     * @param int $page 页码（默认1）
     * @author jason wang <120907037@qq.com>
     * @return bool
     */
    public function getListByPlayid($play_id, $page = 1){
        
        return '';
    }
	
	
	/**
     * 用户信息 关联载入（一对一）
     */
    public function getUcMember(){
        return $this -> hasOne('app\user_center\model\user\Member','uid', 'uid');
    }

    /**
     * 用户统计 关联载入（一对一）
     */
    public function getUcMemberCount(){
        return $this -> hasOne('app\user_center\model\user\UcMemberCount','uid', 'uid');
    }

	/**
     * 视频表 关联载入（一对一）
     */
    public function getVideoPlay(){
        return $this -> hasOne('app\video\model\VideoPlay','id', 'play_id');
    }

	/**
     * 是否点赞 关联载入（一对一）
     */
    public function getVideoPlaySupport(){
        return $this -> hasOne('app\video\model\VideoPlaySupport','play_id', 'play_id');
    }
}
